package com.team8.system.service.service;

import com.team8.common.results.Result;
import com.team8.system.pojo.CheckInResult;
import com.team8.system.pojo.CheckInTime;
import com.team8.system.pojo.Person;
import com.team8.system.service.dao.CheckInResultDao;
import com.team8.system.service.dao.CheckInTimeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class CheckInService {

    @Autowired
    private CheckInTimeDao checkInTimeDao;

    @Autowired
    private CheckInResultDao checkInResultDao;

    public List<CheckInTime> selectByFfid(String ffid) {

        Example example = new Example(CheckInTime.class);

        Example.Criteria criteria = example.createCriteria();

        criteria.orLike("ffid", ffid);
        criteria.orEqualTo("ffid", ffid);

        List<CheckInTime> checkInTimes = checkInTimeDao.selectByExample(example);

        return checkInTimes;

    }

    public List<Person> selectByUserId(String userId) {

        List<Person> checkInTimes = checkInTimeDao.selectByUserId(userId);
        return checkInTimes;
    }

    public Result insert(String ffid, Integer personId) {

        CheckInResult checkInResult = new CheckInResult();
        checkInResult.setFfid(ffid);
        checkInResult.setPersonId(personId);
        checkInResultDao.insert(checkInResult);
        return Result.getSuccessInstance();
    }
}
